﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;
using System.Data;

namespace DataAccess
{
    public class NhanVien_Info
    {
        public string manv { get; set; }
        public string hovaten { get; set; }
        public DateTime ngaysinh { get; set; }
        public string diachi { get; set; }
        public string dienthoai { get; set; }
        public int cmnd { get; set; }
        public bool gioitinh { get; set; }
        public string chucvu { get; set; }
        public NhanVien_Info()
        { }
        public static List<NhanVien_Info> All()
        {
            return CBO.FillCollection<NhanVien_Info>(DataProvider.Instance.ExecuteReader("NhanVien_GetAll"));
        }
        public static DataSet GetAll()
        {
            try
            {
                return DataProvider.Instance.ExecuteDataset("NhanVien_GetAll");
            }
            catch (Exception)
            {

                return null;
            }
        }
        public static bool Add(string manv, string hovaten, DateTime ngaysinh, string diachi, string dienthoai, int cmnd, bool gioitinh, string chucvu)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQuery("NhanVien_Insert", manv, hovaten, ngaysinh, diachi, dienthoai, cmnd, gioitinh, chucvu);
                return Convert.ToInt32(rs) > 0;
            }
            catch (Exception e)
            {
                return BatLoi.ThongBao(e.Message);
            }
        }
        public static bool Update(string manv, string hovaten, DateTime ngaysinh, string diachi, string dienthoai, int cmnd, bool gioitinh, string chucvu)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQuery("NhanVien_Update", manv, hovaten, ngaysinh, diachi, dienthoai, cmnd, gioitinh, chucvu);
                return Convert.ToInt32(rs) > 0;
            }
            catch (Exception e)
            {
                return BatLoi.ThongBao(e.Message);
            }
        }
        public static bool Delete(string manv)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("NhanVien_Delete", manv);
                return rs > 0;
            }
            catch (Exception e)
            {
                return BatLoi.ThongBao(e.Message);
            }
        }
        public static List<NhanVien_Info> GetByName(string name)
        {
            try
            {
                return CBO.FillCollection<NhanVien_Info>(DataProvider.Instance.ExecuteReader("NhanVien_GetByName", name));
            }
            catch
            {
                return null;
            }
        }
        public static List<NhanVien_Info> GetByID(string manv)
        {
            try
            {
                return CBO.FillCollection<NhanVien_Info>(DataProvider.Instance.ExecuteReader("NhanVien_GetByID", manv));
            }
            catch
            {
                return null;
            }
        }
        public static DataSet GetByMaSo(string manv)
        {
            try
            {
                return DataProvider.Instance.ExecuteDataset("NhanVien_GetByID", manv);
            }
            catch
            {
                return null;
            }
        }
        public static List<NhanVien_Info> GetByCMND(string soCMND)
        {
            try
            {
                return CBO.FillCollection<NhanVien_Info>(DataProvider.Instance.ExecuteReader("NhanVien_GetByCMND", Convert.ToInt32(soCMND)));
            }
            catch
            {
                return null;
            }
        }

    }
}
